<div class="frame_addfactoryDiv">
  <form name="buyerContactForm" id="buyerContactForm" method="post" target="_top">
  <table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#c8d9e9">
    <tr>
      <td width="20%" class="ri-bbgg">The number of virtual currency recharge：</td>
      <td width="80%" class="le">
	  	<input type="text" maxlength="10" value="" name="virtual" />
	  </td>
    </tr>
	<tr>
      <td width="20%" class="ri-bbgg">You need to pay：</td>
      <td width="80%" class="le">
	  	<input readOnly type="text" value="" name="virtualMoney" /> $
	  </td>
    </tr>
	<tr>
      <td width="20%" class="ri-bbgg">Payment method</td>
      <td width="80%" class="le">
		<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#CEE7FF" style="border-collapse:collapse">
			<tr>
				<th>Payment</th>
				<th>Description</th>
				<th>Select</th>
			</tr>
			<tr>
				<td>Paypal</td>
				<td>Paypal ( Procedure charge = Total fee × <?=EXPRESS_RATE-1?> )</td>
				<td><input type="radio" value="" name="payment" onclick="changePayment('paypal')" /></td>
			</tr>
			<tr>
				<td>Western Union</td>
				<td>Western Union</td>
				<td><input type="radio" value="" name="payment" onclick="changePayment('west')" /></td>
			</tr>
			<tr>
				<td>T/T</td>
				<td>T/T</td>
				<td><input type="radio" value="" name="payment" onclick="changePayment('tt')" /></td>
			</tr>
			<tr>
				<td colspan='3' style="text-align:left">
					<div><strong>Total: </strong> $USD <span id="totalMoney">0</span></div>
				</td>
			</tr>
		</table>
	  </td>
    </tr>
	<tr>
      <td colspan="2" align="center">
	  	<input type="hidden" name="lang" value="en">
		<input type="hidden" name="currency" value="USD">
		<input type="hidden" name="orderid" value="<?=$this->orderid?>">
		<input type="hidden" name="cmd" value="_xclick">
		<input type="hidden" name="business" value="<?=PAYPAL_ACCOUNT?>"> 
		<input type="hidden" name="item_name" value="Virtual money recharge">
		<input type="hidden" name="item_number" value="Item Number Goes Here "> 
		<input type="hidden" name="amount" value="<?=$this->total?>"> 
		<input type="hidden" name="no_shipping" value="1"> 
		<input type="hidden" name="no_note" value="1"> 
		<input type="hidden" name="currency_code" value="USD"> 
		<input type="hidden" name="notify_url" value="<?=MY_URL?>/buyer-recharge-paypalreceive?uid=<?=$this->uid?>"> 
		<input type="hidden" name="return" value="<?=MY_URL?>/adminb-info-virtual">
		<input type="hidden" name="cancel_return" value="<?=MY_URL?>/adminb-info-virtual">  
	  	<input onclick="checkForm()" type="button" value="Pay now" />
	  </td>
    </tr>
  </table>
</div>
<script>
var paypalTotal=0;
var total=0;
function changePayment(payment){
	if(payment=='paypal'){
		$('#totalMoney').html(paypalTotal);
		$('input[name="amount"]').val(paypalTotal);
		$('#buyerContactForm').attr('action','<?=PAYPAL_URL?>');
		$('#buyerContactForm').attr('target','_top');
	}else if(payment=='alipay'){
		$('#totalMoney').html("<?=$this->total?>");
		$('input[name="amount"]').val(total);
		$('#buyerContactForm').attr('action','adminb-recharge-dopay?payment=alipay');
	}else if(payment=='west'){
		$('#totalMoney').html(total);
		$('input[name="amount"]').val(total);
		$('#buyerContactForm').attr('action','adminb-recharge-dopay?payment=west');
		$('#buyerContactForm').attr('target','_self');
	}else if(payment=='tt'){
		$('#totalMoney').html(total);
		$('input[name="amount"]').val(total);
		$('#buyerContactForm').attr('action','adminb-recharge-dopay?payment=tt');
		$('#buyerContactForm').attr('target','_self');
	}
}

var virtual_exchange_rate="<?=$this->virtual_exchange_rate?>";
$('input[name="virtual"]').keyup(
	function(){
		if(!/^\d+$/.test($(this).val())){
			$(this).val($(this).val().replace(/[^\d]+/g,''));
		}
		$('input[name="payment"]').attr('checked',false);
		$('input[name="virtualMoney"]').val($(this).val()/virtual_exchange_rate);
		total=$(this).val()/virtual_exchange_rate;
		$('#totalMoney').html(total);
		paypalTotal=formatfloat(total*<?=EXPRESS_RATE?>,2);
	}
);
$('input[name="virtual"]').click(
	function(){
		$('input[name="payment"]').attr('checked',false);
	}
);
$('input[name="virtual"]').blur(
	function(){
		if(!/^\d+$/.test($(this).val())){
			$(this).val($(this).val().replace(/[^\d]+/g,''));
		}
		$('input[name="payment"]').attr('checked',false);
		$('input[name="virtualMoney"]').val($(this).val()/virtual_exchange_rate);
		$('#totalMoney').html(total);
		total=$(this).val()/virtual_exchange_rate;
	}
);
function checkForm(){
	if(!numTest($('input[name="virtual"]').val())){
		alert('Please input the number of virtual money you want to buy!');
		return false;
	}
	if(!checkChecked()){
		alert("Please select the payment method!");
		return false;
	}
	$('#buyerContactForm').submit();
}
function checkChecked(){
	var has=false;
	$('input[name="payment"]').each(
		function(){
			if($(this).attr('checked')==true){
				has=true;
			}
		}
	);
	return has;
}

</script>